<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />


    <!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="lib/daterangepicker/daterangepicker.css" />
    <!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>订单打印列表</title>
    <style type="text/css">
        /*.dropDown{min-width: 120px;}*/

        .s-state {
            min-width: 120px;
        }

        .s-state label {
            width: 100%;
            display: block;
            height: 30px;
            line-height: 30px;
            padding: 0 20px;
            min-width: 60px;
        }

        .fun-edit input {
            width: 80px;
        }

        .label {
            font-weight: 500;

        }
        .order-header td{
			background: #f7f6fb;
		}
		.goods-list{
			display: box;
			display: -webkit-box;
		}
		.goods-list+.goods-list{
			margin-top: 10px;
		}
		.goods-list .cont{
			box-flex: 1;
			-webkit-box-flex: 1;
		}
		.goods-list .icon{
			width: 60px;
			height: 60px;
			margin-right: 10px;
		}
		.goods-list .icon img{
			width: 100%;
		}
		.goods-list .intro{
			display: box;
			color: #8f8f8f;
			box-pack: justify;
			display: -webkit-box;
			-webkit-box-pack: justify;
		}
    </style>
</head>

<body>
    <!-- <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> -->
    <!--startprint-->
    <div id="printcontent"></div>
    <!--endprint-->
    <div id="contenthtml">
        <nav class="breadcrumb" style="display: none;">
            <i class="Hui-iconfont">&#xe67f;</i>
            <a _href="welcome.html" class="fun-toindex" href="javascript:;">首页</a>
            <span class="c-gray en">&gt;</span> 订单管理
            <span class="c-gray en">&gt;</span> 订单打印列表
            <a class="btn btn-success radius r mr-20 reload" style="line-height:1.6em;margin-top:3px"
                href="javascript:;" title="刷新">
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
            <span class="r" style="margin-top: -2px; box-sizing: border-box;"></span>
                
        </nav>

        <div class="pd-10 text-r">
                <span style="width:380px; position:relative;">
                    打印日期：
                    <input name="time" type="text" id="date-range1" class="input-text datainp" style="width:300px">
                    <i class="Hui-iconfont i-close" id="inputclear" >&#xe706;</i>
                </span>
                <span style="width:180px; position:relative;">
                    省市：
                    <select name="province_id" id="province_id" class="select" style="width: auto; height: 31px; vertical-align: middle;">
                        <option value="" selected="">选择省</option>
                    </select>
                    <select name="city_id" id="city_id" class="select" style="width: auto; height: 31px; vertical-align: middle;">
                        <option value="" selected="">选择市</option>
                    </select>
                </span>
                <span style="position:relative">
                    <input type="text" name="k"  placeholder="订单编号、收货人" style="width:200px" class="input-text">
                    <i class="Hui-iconfont i-close" id="inputclear" style="line-height: 33px">&#xe706;</i>
                </span>
                <button id="search" class="btn btn-success">
                    <i class="Hui-iconfont">&#xe665;</i> 搜索</button>

             

                <li class="dropDown dropDown_hover">
                    <a href="#" class="dropDown_A">
                        <button class="btn btn-success">
                            <i class="Hui-iconfont">&#xe652;</i>批量打印</button>
                    </a>
                    <ul class="dropDown-menu radius box-shadow">
                        <li class='fun-allprint' data-type="1">
                            <a href="javascript:;">百世快递</a>
                        </li>
                        <li class='fun-allprint' data-type="2">
                            <a href="javascript:;">邮政快递</a>
                        </li>
                        <li class='fun-allprint' data-type="3">
                            <a href="javascript:;">圆通快递</a>
                        </li>

                    </ul>
                </li>
                <li class="dropDown dropDown_hover">
                    <a href="#" class="dropDown_A">
                        <button class="btn btn-success">导出EXCEL</button>
                    </a>
                    <ul class="dropDown-menu radius box-shadow">
                        <li id='exportorder'>
                            <a href="javascript:;">订单EXCEL</a>
                        </li>
                        <li id='exportgoods'>
                            <a href="javascript:;">商品EXCEL</a>
                        </li>
                    </ul>
                </li>
                <!-- <button id="fun-allprint" class="btn btn-success" data-type="2"><i class="Hui-iconfont">&#xe665;</i> 百事批量打印</button> -->
            
        </div>

        <div class="pd-10">

            <div class="mt-20">
                <table class="table table-border table-bordered table-bg table-hover table-sort" id="categorylist">
                    <thead style="display: none;">
                        <tr class="text-c sort0">
                            <th width="40" class="valueid">
                                <input name="" type="checkbox" value="">
                            </th>
                            <th width="60" class="fun-sort2" data-name="order_id" data-flag="0">订单ID</th>
                            <th width="150">订单编号</th>
                            <th width="150">购买产品</th>
                            <th width="100">购买者</th>
                            <th width="100">收货人/联系电话</th>
                            <!-- <th width="60">收货人</th> -->
                            <th width="80">地址</th>
                            <th width="80">备注</th>
                            <!-- <th width="40">地址</th> -->
                            <th width="100" class="fun-sort2" data-name="order_time" data-flag="0">下单时间</th>
                            <!-- <th width="100" class="fun-sort2" data-name="handle_addtime" data-flag="0">打印时间</th> -->

                            <th width="120" class="fun-sort2" data-name="total_quan" data-flag="0">金额</th>
                            <th width="120">状态</th>
                            <!-- <th width="40">操作</th> -->
                        </tr>
                    </thead>
                    <tbody id="content_sp">

                    </tbody>
                </table>
            </div>

            <div class="cl pd-5 bg-1 bk-gray mt-10" id="operation">
                <!-- <a href="javascript:;" class="btn btn-warning l mr-10 mt-5 radius fun-all" data-type="stop"><i class="Hui-iconfont">&#xe6de;</i> 批量关闭</a> 
		<a href="javascript:;" class="btn btn-success l mr-10 mt-5 radius fun-all" data-type="start"><i class="Hui-iconfont">&#xe603;</i> 批量开启</a> 
		<a href="javascript:;" class="btn btn-danger l mr-10 mt-5 radius fun-all" data-type="del"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
		 -->
                <span class="r pt-5" style="line-height: 35px;" id="page"></span>
                <span class="r mr-10" style="line-height: 40px;" id="dataall"></span>

            </div>


        </div>
    </div>
    <!-- 模版 -->
<script id="test" type="text/html">
<% for (x in list) { %>
	<tr class="order-header">
		<td class="valueid" colspan="14">
			<div style="display: box;display: -webkit-box;">
				<div style="margin-right: 30px;"><input name="" type="checkbox" value="<%=list[x].order_id%>"></div>
				<div style="margin-right: 30px;">订单编号：<span><%=list[x].order_number%></span></div>
				<div style="margin-right: 30px;">订单总金额：<span>&yen;<%=list[x].total_fee%></span></div>
				<div style="margin-right: 30px;box-flex: 1;-webkit-box-flex: 1;">创建时间：<span>&yen;<%=list[x].order_time%></span></div>
				<div>订单状态：<span><%=list[x].order_state_cn%><%if(list[x].order_state==50 && list[x].cancel_reason!==''){%>(<%=list[x].cancel_reason%>)<%}%></span></div>
			</div>
		</td>
	</tr>
	<tr class="text-c va-m sort1" >
		<td class="text-l" >
			<a href="javascript:;" onClick="_open('订单详情','order-detail.html?oid=<%=list[x].order_id%>','90%','70%',true)" style="text-decoration: underline;">
				<%=list[x].order_id%>
			</a>
		</td>
		<td class="text-l">
			<% for (g in list[x].goods) { %>
			<div class="goods-list">
				<div class="icon">
					<img src="<%=list[x].goods[g].goods_image%>" />
				</div>
				<div class="cont">
					<div class="name"><%=list[x].goods[g].goods_name%></div>
					<div class="intro">
						<div class="num">数量：<%=list[x].goods[g].num%></div>
						<div class="price">金额：<%=list[x].goods[g].goods_cost%></div>
					</div>
				</div>
			</div>
			<%}%>
		</td>
		<td>
			<div>总价：<%=list[x].total_fee%></div>
			<div>U币：<%=list[x].total_quan%></div>
			<div>实付：<%=list[x].total_cost%></div>
		</td>
		<td class="fun-search" data-name="user_name" data-value="<%=list[x].user_name%>">
			付款账号：<br />
			<%=list[x].user_name%> (<%=list[x].uid%>)
		</td>
		<td>
			收货人信息：<br />
			<%=list[x].receiver%><br />
			<%=list[x].mobile%><br />
			<%=list[x].province_name%> <%=list[x].city_name%> <%=list[x].address%>
		</td>
		<td class="fun-edit" data-classname="remark">
			<input placeholder="备注" type="text" name="" value="<%=list[x].remark%>">
		</td>
		<td class="td-manage f-18">
			<a href="javascript:;" onClick="_open('订单详情','order-detail.html?oid=<%=list[x].order_id%>','90%','70%',true)" style="font-size: 12px;">
					查看详情
				</a>
<!--  			<a style="text-decoration:none" class="label label-warning radius" onClick="_open('评论列表','order-evaluate.html?orderid=<%=list[x].order_id%>','90%','90%',false)" href="javascript:;" title="评论订单"><i class="Hui-iconfont">&#xe622;</i>评论</a>  -->
		</td>
	</tr>
	<tr style="height: 10px;">
		<td colspan="14" style="background: #fff;position: relative;">
			
		</td>
	</tr>
<%}%>
</script>


    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/H-ui.js"></script>
    <script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
    <script type="text/javascript" src="js/H-ui.admin.js"></script>
    <script type="text/javascript" src="js/template-native.js"></script>
    <script type="text/javascript" src="js/s.js"></script>
    <script language="javascript" src="js/LodopFuncs.js"></script>

    <script type="text/javascript" src="lib/laypage/laypage.js"></script>
    <script type="text/javascript" src="lib/daterangepicker/moment.min.js"></script>
    <script type="text/javascript" src="lib/daterangepicker/jquery.daterangepicker.js"></script>
    <script src="/Manage/js/lazyload.min.js"></script>
    <script type="text/javascript">
        var API = API_ORDERLIST + '?state=10,';
        var kk = API;
        var orderby = '';
        var search = '';
        $("#statebtn").html("待发货");

        var uid = getUrlParam('uid');//用户详情查询使用
        if (uid !== null && uid !== undefined) {
            API = API + '?uid=' + uid;
            // $("nav").hide();
            //    $("#operation").hide();
        }

        loaddata(API, '', true);

        function getArea() {
            $.getJSON(API_AREASELECT, function (data) {
                // if (!checkStatus(data)) return;
                if (data == '') {
                    layer.msg('分类出错', { icon: 5, time: 1000 });
                } else {
                    // 罗列一级分类
                    areaDatas = data.datas;
                    for (i = 0; i < data.datas.length; i++) {
                        $("#province_id").append("<option value='" + data.datas[i].areacode + "' data-areacode='" + data.datas[i].areacode + "'>" + data.datas[i].areaname + "</option>");
                    }
                }
            });
             // 市分类二级联动
             $("#province_id").change(function () {
                var ii = $('#province_id option:selected').data("areacode");
                console.log(ii,"2222")
                $("#city_id").empty();
                $("#city_id").append("<option value='0' >选择市</option>");
                $.getJSON(API_AREASELECT+'?pid='+ii,function(data){
                    for(i=0; i<data.datas.length; i++){
                        $("#city_id").append("<option value='"+data.datas[i].areacode+"'>"+data.datas[i].areaname+"</option>");
                    }
                })
                // if (areaDatas[ii]['child']) {
                //     var data2 = areaDatas[ii]['child'];
                //     for (j = 0; j < data2.length; j++) {
                //         $("# city_id").append("<option value='" + data2[j].areacode + "' >" + data2[j].areaname + "</option>");
                //     }
                // }
            })
        }
        getArea();

        $('#date-range1').dateRangePicker({
            startOfWeek: 'monday',
            separator: ' 至 ',
            format: 'YYYY-MM-DD HH:mm',
            autoClose: true,
            time: {
                enabled: true
            },
            defaultTime: moment().startOf('day').toDate(),
            defaultEndTime: moment().endOf('day').toDate()
        });

        var print_num = 0;
        var isshow = true;
        // 批量打印的单个循环
        function doPrint(id, type, obj) {
            var eidturl = API_MIANDAN + "?oid=" + id + '&type=' + type;
            if (type == 1) {
                var text = "百世快递包裹"
            } else if (type == 2) {
                var text = "邮政快递包裹"
            } else if (type == 3) {
                var text = "圆通快递"
            }
            $.getJSON(eidturl, function (data) {
                // if(!checkStatus(data)) return;//判断登录

                if (data.status == 0) {
                    // layer.msg("数据加载错误", {icon:2,time:1000});
                } else {
                    // LODOP=getLodop();         
                    console.log("print")
                    print_num++;
                    LODOP.PRINT_INIT("");
                    LODOP.ADD_PRINT_HTM(0, 0, "100%", "100%", data.datas.PrintTemplate);

                    LODOP.PRINT();

                    obj.closest("tr").find("td.td-indexshow").html('<b>已发货</b><br>' + text + '<br>' + data.datas.Order.LogisticCode)
                }

            })
        }

        // 批量打印
        $(document).on('click', 'li.fun-allprint', function () {


            LODOP = getLodop();
            console.log(isshow)

            if (isshow) {
                layer.load();
                print_num = 0
                var type = $(this).data("type");
                if (type == 1) {
                    var name = "百世"
                } else if (type == 2) {
                    var name = "邮政"
                } else if (type == 3) {
                    var name = "圆通"
                }
                var allnum = $("#content_sp .valueid input[type='checkbox']:checked").length;
                if ($("#content_sp .valueid input[type='checkbox']:checked").length < 1) {
                    layer.closeAll();
                    layer.msg('请选择要操作的内容!', { icon: 2, time: 2000 });
                } else {
                    var ids = "";

                    $.ajaxSettings.async = false;

                    $("#content_sp .valueid input[type='checkbox']:checked").each(function (e) {
                        var obj = $(this);
                        ids = ids + $(this).val() + ",";
                        doPrint($(this).val(), type, obj);
                    })

                    var text = "你选中了" + allnum + "张，打印了" + print_num + "张";
                    layer.closeAll();
                    layer.msg(text, { icon: 1, time: 3000 });

                    console.log(ids)
                }
            } else {

                layer.msg("尚未安装打印插件", { icon: 2, time: 3000 });

            }





        })


        $(document).on('click', 'a.fun-print', function () {
            var oid = $(this).data("oid");
            var type = $(this).data("type");
            var eidturl = API_MIANDAN + "?oid=" + oid + '&type=' + type;
            var that = $(this);
            if (type == 1) {
                var text = "<b>待收货</b><br>百世快递包裹<br>";
            } else if (type == 2) {
                var text = "<b>待收货</b><br>邮政快递包裹<br>";
            } else if (type == 3) {
                var text = "<b>待收货</b><br>圆通快递包裹<br>";
            }
            $.getJSON(eidturl, function (data) {
                if (!checkStatus(data)) return;//判断登录

                if (data.datas == '') {
                    layer.msg("数据加载错误", { icon: 2, time: 1000 });
                } else {
                    that.parent().prev().html(text + data.datas.Order.LogisticCode)

                    $("#printcontent").html(data.datas.PrintTemplate);
                    $("#contenthtml").hide();
                    window.print();
                    $("#contenthtml").show();
                    $("#printcontent").empty();

                }

            })
        })

        // 退款
        $(document).on('click', 'span.fun-refund', function () {
            var flag = $(this).data("flag");
            var oid = $(this).data("orderid");
            console.log(oid);
            var that = $(this);
            if (flag == 1) {
                layer.confirm('退款后,券和运费将打到用户账户?', function (index) {
                    layer.close(index);
                    console.log("同意")

                    $.post(API_ORDERLIST, {
                        oid: oid,
                        type: 'refund',
                    }, function (data) {
                        // data=eval("( "+data+" )");
                        if (!checkStatus(data)) return;

                        that.parent().html("已同意√")


                    }, 'json')
                })
            } else if (flag == 2) {
                layer.use('extend/layer.ext.js', function () {
                    layer.prompt({
                        title: '拒绝理由',
                    }, function (val, index) {
                        layer.close(index);
                        console.log("处理不同意")

                        $.post(API_ORDERLIST, {
                            oid: oid,
                            type: 'norefund',
                        }, function (data) {
                            if (!checkStatus(data)) return;
                            that.parent().html("已拒绝×")
                        }, 'json')
                    })
                })
            }

        })

        $(document).on('click', '#search', function () {
            // if(kk.indexOf('?') >= 0){
            //        kk=kk+"&";
            //    }else{
            //    }
            kk = API + "&";

            // 订单状态
            var state = '';
            var name = '状态：';
            $("input[name='state']:checked").each(function () {
                state += $(this).val() + ',';
                name += $(this).data("name") + ',';
            })
            var province_id = $("#province_id").val();
            var city_id = $("#city_id").val();
            $("#statebtn").html(name);

            // 参与活动
            // var state2='';
            // var name2='活动：';
            // $("input[name='state2']:checked").each(function(){ 		
            // 	state2 += $(this).val()+'=1&';
            // 	name2+=$(this).data("name")+','; 		
            // })
            // $("#activity").html(name2);

            var param = [
                'k='+encodeURI(document.querySelector('input[name=k]').value),
                // 'user_name='+encodeURI(document.querySelector('input[name=user_name]').value),			
                // 'goods_name='+encodeURI(document.querySelector('input[name=goods_name]').value),			
                'state=' + state,
                'handle_addtime=' + document.querySelector('input[name=time]').value,
                'province_id=' + province_id,
                'city_id=' + city_id,
                // state2,
            ];

            search = param.join('&');
            kk = kk + orderby + search;
            loaddata(kk, 1);

        })

        $(document).on('click', '#exportorder', function () {
            var state = '';
            $("input[name='state']:checked").each(function () {
                state += $(this).val() + ',';
            })



            var param = [

                'state=' + state,
                'handle_addtime=' + document.querySelector('input[name=time]').value,
            ];
            param = param.join('&');
            window.open(API_EXPORT_ORDER + '?' + param + orderby);
            console.log(API_EXPORT_ORDER + '?' + param + orderby)
        })

        $(document).on('click', '#exportgoods', function () {
            var state = '';
            $("input[name='state']:checked").each(function () {
                state += $(this).val() + ',';
            })

            var param = [

                'state=' + state,
                'handle_addtime=' + document.querySelector('input[name=time]').value,
            ];
            param = param.join('&');
            window.open(API_EXPORT_ORDERGOODS + '?' + param + orderby);
            console.log(API_EXPORT_ORDERGOODS + '?' + param + orderby)
        })





    </script>

</body>

</html>